<template>
  <div class="box">
    <div class="header">
      <van-nav-bar title="短信验证登录/注册" left-arrow @click-left="$router.back()" />
    </div>
    <main class="content">
      <van-form @submit="onSubmit">
        <van-cell-group inset>
          <van-field v-model="username" name="username" label="手机号" placeholder="手机号"
            :rules="[{ required: true, message: '请填写用户名' }, { pattern: /^1[3-9]\d{9}$/, message: '请填写正确的手机号' }]" />
          <van-field v-model="password" type="password" name="password" label="密码" placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]" />
          <van-field v-model="sms" center clearable label="短信验证码" :rules="[{ pattern: /^\d{6}$/, message: '请填写正确的验证码' }]"
            placeholder="请输入短信验证码">
            <template #button>
              <van-button size="small" type="primary" @click="submit">{{ msg }}</van-button>
            </template>
          </van-field>
        </van-cell-group>
        <div style="margin: 16px;">
          <van-button round block type="primary" native-type="submit">
            登录
          </van-button>
        </div>
      </van-form>
    </main>
    <div class="tat">
      <p>账户登录</p>
      <p>验证码收不到</p>
    </div>
  </div>
</template>

<script setup>
import request from '@/tool/request'
import { ref } from 'vue'
import { useRouter } from 'vue-router';
const router = useRouter()
const username = ref('');
const password = ref('');

const onSubmit = (values) => {
  console.log('submit', values);
  request.post('/login', {
    nameuser: username.value,
    password: password.value
  }).then(res => {
    if (res.data.code == 200) {
      localStorage.setItem('token', res.data.token)
      localStorage.setItem('username', username.value)
      router.push('/user')
    }

  })
};
const timer = ref()
const time = ref(60)
const msg = ref(60)
const submit = () => {
  timer = setInterval()
}
</script>

<style lang="scss" scoped>
.tat {
  display: flex;
  justify-content: space-between;
}
</style>